package com.broad.commerce.code.services.business;

import com.broad.commerce.code.base.AbstractJavaService;
import com.broad.commerce.code.modules.BaseModule;
import com.broad.commerce.code.modules.business.InterfaceModule;
import com.broad.commerce.code.services.base.BaseInterfaceService;
import com.broad.commerce.web.exception.ServiceException;
import org.springframework.stereotype.Service;

/**
 * @author stephen
 * @version V1.0
 * @date 2022-02-08 18:54
 * @description: ControllerModuleService
 **/
@Service
public class InterfaceModuleService extends AbstractJavaService {

	/**
	 * Create entity code string.
	 * @param baseModule the base module
	 * @return the string
	 */
	@Override
	public String createClassCode(BaseModule baseModule) {
		if (!(baseModule instanceof InterfaceModule)) {
			throw new ServiceException("传入参数类型错误！应为 InterfaceModule");
		}
		return super.createClassCode(baseModule);
	}

	/**
	 * Create import code.
	 * @param sb the sb
	 * @param baseModule the base module
	 */
	@Override
	protected void createImportCode(StringBuilder sb, BaseModule baseModule) {
		InterfaceModule interfaceModule = (InterfaceModule) baseModule;
		//@off
		sb.append("import ").append(interfaceModule.getEntityFullClassName()).append(";\n")
		  .append("import ").append(interfaceModule.getModelFullClassName()).append(";\n")
		  .append("\n")
		  .append("import java.util.List;").append("\n")
		  .append("\n");//@on
	}

	/**
	 * Create annotation code.
	 * @param sb the sb
	 * @param baseModule the base module
	 */
	@Override
	protected void createAnnotationCode(StringBuilder sb, BaseModule baseModule) {
		//sb.append("@SuppressWarnings(\"ALL\")\n");
	}

	/**
	 * Create class start tag.
	 * @param sb the sb
	 * @param baseModule the base module
	 */
	@Override
	protected void createClassStartTag(StringBuilder sb, BaseModule baseModule) {
		InterfaceModule interfaceModule = (InterfaceModule) baseModule;
		BaseInterfaceService.createClassStartTag(sb, interfaceModule);
	}

	/**
	 * Create class content.
	 * @param sb the sb
	 * @param baseModule the base module
	 */
	@Override
	protected void createClassContent(StringBuilder sb, BaseModule baseModule) {
		InterfaceModule interfaceModule = (InterfaceModule) baseModule;
		BaseInterfaceService.createClassContent(sb, interfaceModule);
	}
}
